package com.zzyl.nursing.controller;

import com.zzyl.nursing.dto.Dto;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * @author yhn
 * @version 1.0
 * @description
 * @date 2025/10/20 16:19
 */
@RestController
@RequestMapping("/test" )
@RequiredArgsConstructor
public class TestAI {

    private final ChatClient chatClient;
    private final ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @GetMapping(value = "/chat" )
    public Flux<String> chat(@RequestParam String massage) {
        return chatClient.prompt()
                .user(massage) //前端用户输入的文字，与大模型进行沟通
                .stream()//使用流式输出，可以配合前端 实现打字机效果
                .content();//得到大模型响应的内容
    }

    @PostMapping("/simple1" )
    public String simpleChat(@RequestBody Dto dto) {
        return chatClient.prompt(dto.getMessage())
                .advisors(a -> a
                        .param(AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY, dto.getId())
                        .param(AbstractChatMemoryAdvisor.CHAT_MEMORY_RETRIEVE_SIZE_KEY, 100)
                ).call().content();
    }
}
